|
|
 |
|
|
|
|
vntVariable = 5.5
...
...
vntVariable = "Hi There" |
|
|
|
|
|
|
|
|
As you can see in this code snippet, after declaring a variable as a Variant data type, you can change it from an Integer to a Single and then later you can change it to a String. |
|
|
|
|
|
|
|
|
When using the Variant data type as a string, and the string contains a numeric value such as 10 or 20, you need to be careful when concatenating two of these types of strings together. Lets look at an example of what happens. |
|
|
|
|
|
|
|
|
Examples Filename: Variants.frm |
|
|
|
|
|
|
|
|
The Variants.frm file shows you different results based on how you concatenate two variant strings together. As you can see in Figure 6.4, the first three values differ. Visual Basic has two different methods for concatenating strings together: using a plus sign (+) and using an ampersand (&). Lets take a look at the code for each one of these command buttons to see the difference. |
|
|
|
|
|
|
|
|
Figure 6.4
Variant examples. |
|
|
|
|
| Two String Variant Variables 1. Double-click the + Strings command button to view the following code: | | Private Sub cmdStrConcat_Click ()
Dim vntStr1 As Variant ' Declared as Variant
Dim vntStr2 As Variant ' Declared as Variant
vntStr1 = "10" ' Value is a String |
|
|
|